import $api from '@/http/api.js'

export default {
    namespaced: true,
    state: {
        rows: [],
        pages: 0,
        total: 0
    },
    mutations: {
        SET_DATA(state, payload) {
            state.rows = payload;
            state.pages = payload.pages;
            state.total = payload.total;
        }
    },
    actions: {
        // 获取所有套餐
        async getDataAsync(context, pageData) {
            const {data} = await $api.meals.getAllMeal(pageData);
            if(data.meta.status == 200) {
                context.commit('SET_DATA', data.data)
            }
        },
        // 新增一个套餐
        async addOneDataAsync(context,data) {
            return await $api.meals.addMeal(data);
        },
        // 修改一个套餐
        async updateOneDataAsync(context, data) {
            return await $api.meals.updateMeal(data);
        },
        // 取消一个会员
        async cancleOneDataAsync(context, data) {
            return await $api.meals.cancleMember(data);
        },
    }
}